/**
 * 要求定义一个类A，该类A只能被实例化为一个唯一的对象！(单例模式).
 * 本题对应的公共类和main函数定义如下：
 */
class A {
    private volatile static A instance = null;
    private A() { }
    public static A getInstance() {
        if (instance == null) {
            synchronized (A.class) {
                if (instance == null)
                    instance = new A();
            }
        }
        return instance;
    }
}
public class Test6 {
    public static void main(String[] args) {
        A o1 = A.getInstance();
        A o2 = A.getInstance();
        if (o1.equals(o2)) {
            System.out.println("o1 and o2 are the same object!");
        }
    }
}
